// MyMenu.cpp : implementation file
//

#include "stdafx.h"
//#include "AVIButtonDemo.h"
#include "MyMenu.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyMenu

CMyMenu::CMyMenu()
{
}

CMyMenu::~CMyMenu()
{
}



/////////////////////////////////////////////////////////////////////////////
// CMyMenu message handlers

void CMyMenu::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	CBrush IconBkBrush;
	BITMAP bmp;
	CDC mem;
	IconBkBrush.CreateSolidBrush(RGB(235,236,238));
	mem.CreateCompatibleDC(pDC);
	//CBrush *old = mem.SelectObject(&IconBkBrush);
	ItemData* lpItemData;
	lpItemData = (ItemData*)lpDrawItemStruct->itemData;
	COLORREF clrBackGround = lpItemData->clrBackGround;
	COLORREF clrSelectColor = lpItemData->clrSelectColor;
	pDC->SetBkMode(TRANSPARENT);
	CBrush BackBrush(clrBackGround);
	//pDC->FillRect(&lpDrawItemStruct->rcItem,&BackBrush);
	CRect rect,rectIcon;
	rect = lpDrawItemStruct->rcItem;
	rectIcon.left = rect.left;
	rectIcon.top = rect.top;
	rectIcon.right = rect.left + 26;
	rectIcon.bottom = rect.top +24;

	pDC->FillRect(&rect,&BackBrush);
	pDC->FillRect(&rectIcon,&IconBkBrush);
	CRect BmpBlock = lpItemData->BmpBlock;
	/*pDC->BitBlt(BmpBlock.left,BmpBlock.top,BmpBlock.right,
		BmpBlock.bottom,&mem,0,0,SRCCOPY);*/
	CBitmap bitmap;
	bitmap.LoadBitmap(lpItemData->nIconID);
	bitmap.GetBitmap(&bmp);
	CBitmap *old = mem.SelectObject(&bitmap);
	rectIcon.DeflateRect(8,8);
	pDC->StretchBlt(rectIcon.left,rectIcon.top,11,11,&mem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
	CString ItemTitle;
	ItemTitle.Empty();
	ItemTitle = lpItemData->ItemTitle;
	pDC->DrawText(ItemTitle,&lpDrawItemStruct->rcItem,DT_CENTER|DT_VCENTER|DT_SINGLELINE);

	if (lpDrawItemStruct->itemState & ODS_SELECTED)
	{
		CBrush sel(clrSelectColor);
		pDC->FillRect(&rect,&sel);
		pDC->DrawText(ItemTitle,&lpDrawItemStruct->rcItem,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		pDC->StretchBlt(rectIcon.left,rectIcon.top,11,11,&mem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
	/*	pDC->BitBlt(BmpBlock.left,BmpBlock.top,BmpBlock.right,
		BmpBlock.bottom,&mem,0,0,SRCCOPY);	*/
		//pDC->DrawIcon(lpDrawItemStruct->rcItem.left+bmp.bmWidth+4,lpDrawItemStruct->rcItem.top,MenuIcon);
		//pDC->DrawText(ItemTitle,&lpDrawItemStruct->rcItem,DT_CENTER|DT_VCENTER|DT_SINGLELINE);

	}
	mem.SelectObject(old);
	ItemTitle.Empty();
}

void CMyMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct )
{
	lpMeasureItemStruct->itemHeight = 24;
	lpMeasureItemStruct->itemWidth = 110;
}

